<!DOCTYPE html>
<html>
<head>
    <title>LUI组件库</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Pragma" content="no-cache">
    <meta name="keywords" content=""/>
    <meta name="description" content="" />
    <link rel="icon" href="images/icon/lui.png">
   
    <link rel="stylesheet" type="text/css" href="css/lui.css" />
</head>
<body>
     <div class="ui_page_wrap">
        <header class="ui_page_hd"><a href="javascript:history.go(-1);" class="ui_back"></a>模态框/弹出层</header>
        <div class="ui_page_bd">
            <p class="ui_con_block">
                alert,confirm,弹出层。
            </p>
            <div class="nav_tab_wrap">
                <nav class="ui_capsule_tab flexbox" id="js_tabs">
                    <a href="javascript:;" class="flexItem on" id="js_alert">alert</a>
                    <a href="javascript:;" class="flexItem" id="js_confirm">confirm</a>
                    <a href="javascript:;" class="flexItem" id="js_modal_ipt">带输入框</a>
                </nav>
            </div>

            <br>
            <div class="p10">
                <button type="button" class="ui_btn" onclick="togglePopup()">普通popup</button>
            </div>
             <div class="p10">
                <button type="button" class="ui_btn" onclick="openPage('#j-popup1')">底部弹出popup</button>
            </div>
            <div class="p10">
              <button type="button" class="ui_btn" onclick="openPage('#j-popup2');toggleMask()">底部弹出非全屏popup</button>
            </div>
        </div>
    </div>

    <!--普通popup-->
    <aside class="ui_mask" id="j-mask-normal" onclick="togglePopup()"></aside>
    <aside class="ui_popup ui_popup_center" id="j-popup-normal">
        <div class="ui_popup_inner">   
          <main class="ui_popup_body">
            普通popup
          </main>
        </div>
    </aside>


    <!--底部弹出层1-->
    <aside class="ui_popup modal_out" id="j-popup1">
        <div class="ui_popup_inner">   
          <header class="ui_popup_header">
              <h2 class="ui_popup_title">底部弹出层标题</h2>
              <a href="javascript:closePage('#j-popup1');" class="ui_close_dialog"></a>
          </header>
          <main class="ui_popup_body">
              <p class="ui_con_block">底部弹出层内容</p>   
          </main>
        </div>
    </aside>

    <!--底部弹出层2-->
    <aside class="ui_mask" id="j-mask" onclick="closePage('#j-popup2');toggleMask()"></aside>
    <aside class="ui_popup ui_popup_round modal_out" id="j-popup2" style="top:5%">
      <div class="ui_popup_inner">
        <header class="ui_popup_header">
          <h2 class="ui_popup_title">底部弹出层标题</h2>
          <a href="javascript:closePage('#j-popup2');toggleMask()" class="ui_close_dialog"></a>
        </header>
        <main class="ui_popup_body">
          <p class="ui_con_block">底部弹出层内容</p>
        </main>
      </div>
    </aside>

<script type="text/javascript" src="js/lui.js"></script>
<script type="text/javascript">
    lui.selector('#js_tabs').onclick = function(e){
        var _id = e.target.id;
        if (_id == 'js_alert') {
             lui.showModal({
                content:'alert',
                showCancel:false,
                confirm:function(){
                   lui.showModal({
                        content:'呵呵',
                        confirm:function(){
                            console.log('confirm');
                        }
                    });
                }
            });
        }else if (_id == 'js_confirm') {
             lui.showModal({
                content:'confirm',
                showCancel:true,
                cancel:function(){
                   console.log('cancel');
                },
                confirm:function(){
                    console.log('confirm');
                }
            });
        }else if(_id == 'js_modal_ipt'){
            var val;
            lui.showModal({
                content:'<input type="text" placeholder="请输入" class="ui_popup_ipt" id="ipt"/>',
                beforeHide:function(){
                    val = lui.selector('#ipt').value;
                },
                confirm:function(){                    
                    console.log(val);
                }
            });
        }
    };


    function openPage(el){
        lui.coverHandler(el,{
            open:function(){
                console.log('open');
            }
        });
    }

     function closePage(el){
        lui.coverHandler(el,{
            close:function(){
                console.log('close');
            }
        });
    }
    
    function toggleMask(){
      var el = document.querySelector('#j-mask');
      el.classList.toggle('ui_mask_active');
    }

    function togglePopup(){
      var mask = document.querySelector('#j-mask-normal')
      var popup = document.querySelector('#j-popup-normal')
      var maskStyle = window.getComputedStyle(mask)
      var popupStyle = window.getComputedStyle(popup)
      mask.style.display = maskStyle.display === 'none' ? 'block' : 'none'
      popup.style.display = popupStyle.display === 'none' ? 'block' : 'none'    }
    
</script>
</body>
</html>